package com.example.redis.rest;

import com.example.redis.service.RedisCommonService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.redisson.api.RBucket;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.core.script.DefaultRedisScript;
import org.springframework.web.bind.annotation.*;

/**
 * redis常規操作Controller
 *
 * @author Roger
 * @since 2021/6/19
 */
@RestController
@RequestMapping("redis/common")
@Api(tags="Redis高级操作api")
public class RedisCommonController {
    @Autowired
    private RedisCommonService redisCommonService;

    @GetMapping("/swap/{value}")
    @ApiOperation(value="lua脚本练习", notes = "lua脚本练习")
    public void swap(@PathVariable String value) {
        redisCommonService.luaSwap(value);
    }

    @GetMapping("/testPipeline")
    @ApiOperation(value="Pipeline练习", notes = "Pipeline练习")
    public void testPipeline() {
        redisCommonService.testPipeline();
    }

    @RequestMapping(value = "/{key}", method = RequestMethod.DELETE)
    @ApiOperation(value="删除key*",notes = "删除key*")
    public Long deleteSUser(@PathVariable("key") String key){
        Long num = redisCommonService.deleteKey(key);
        return num;
    }

}
